//
//  MHCircleInfoBottomViewModel.m
//  MiaoCircle
//
//  Created by 许正荣 on 2018/4/23.
//  Copyright © 2018年 acgera. All rights reserved.
//

#import "MHCircleInfoBottomViewModel.h"
#import "MHComposeViewModel.h"
#import "MHAskViewModel.h"
#import "MHVideoRecordViewModel.h"
#import "MHVideoEditViewModel.h"

@implementation MHCircleInfoBottomViewModel


-(void)initialize
{
    [super initialize];
    @weakify(self);
    
   
    self.pulishCommand = [[RACCommand alloc] initWithSignalBlock:^(NSDictionary *photosDic) {
        @strongify(self)
        NSArray *photos = photosDic[@"photos"];
        NSArray *asserts = photosDic[@"assert"];
        //底部弹出
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        [dic setObject:self.info forKey:MHViewModelUtilKey];
        if (photos) {
            [dic setObject:photos forKey:@"MHViewModelPhotoes"];
        }
        
        if (asserts) {
            [dic setObject:asserts forKey:@"MHViewModelAsserts"];
        }
        MHComposeViewModel *viewModel = [[MHComposeViewModel alloc] initWithServices:self.services
                                                                              params:[dic copy]];
        
        [self.services presentViewModel:viewModel animated:YES completion:nil];

        return [RACSignal empty];
    }];
    
    self.takeVideoCommand = [[RACCommand alloc] initWithSignalBlock:^(id input) {
        @strongify(self)
        
        if ([AXAppDelegate sharedDelegate].inUploading) {
            [MBProgressHUD mh_showTips:@"视频正在上传中，请稍后再试..."];
        }else
        {
//            MHVideoEditViewModel *editModel = [[MHVideoEditViewModel alloc] initWithServices:self.services
//                                                                                        params:nil];
//             [self.services presentViewModel:editModel animated:YES completion:nil];
            
            MHVideoRecordViewModel *viewModel = [[MHVideoRecordViewModel alloc] initWithServices:self.services
                                                                                          params:nil];
            [self.services presentViewModel:viewModel animated:YES completion:nil];
        }
       
        
        return [RACSignal empty];
    }];
    
    
    self.askCommand = [[RACCommand alloc] initWithSignalBlock:^(NSMutableArray *photoes) {
        @strongify(self)
        
        MHAskViewModel *viewModel = [[MHAskViewModel alloc] initWithServices:self.services
                                                                              params:@{MHViewModelUtilKey:self.info}];
        viewModel.info = self.info;
        [self.services pushViewModel:viewModel animated:YES];
        
        return [RACSignal empty];
    }];
}

- (instancetype)initWithServices:(id<MHViewModelServices>)services params:(NSDictionary *)params{
    if (self = [super initWithServices:services params:params]) {
        self.info = params[MHViewModelUtilKey];
        
    }
    return self;
}
@end
